package com.quanquan.store.service.marketActivity;

import com.quanquan.store.entity.marketActivity.MarketActivity;
import com.quanquan.store.repository.marketActivity.MarketActivityRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @ClassName MarketActivityService
 * @Description
 * @Author Owen
 * @Date 2019/9/17 0017 上午 10:31
 * @Version V1.0
 **/
@Service
public class MarketActivityService {

    @Autowired
    private MarketActivityRepository marketActivityRepository;

    /**
     * 根据id查询活动
     * @param id
     * @return
     */
    public MarketActivity getMarketActivityById(Integer id){
        MarketActivity marketActivity = marketActivityRepository.findById(id).orElse(null);
        return marketActivity;
    }

    public List<MarketActivity> getMarketActivityList(){
        List<MarketActivity> list = marketActivityRepository.findAllByStateAndShowStatusAndStartTimeBeforeAndEndTimeAfterOrderBySortAsc(1,true, new Date(), new Date());
        return list;
    }


}
